const util = require('../../utils/util.js');
const bmap = require('../../libs/bmap-wx.min');
const wx = require('../../libs/wx.js');
const config = require('../../config');
const ak = config.ak;
let wxMarkerData = [];
const app = getApp();
const Page = require('../../libs/BasePage');
Page({
    data: {
        markers: [],
        latitude: '',
        longitude: '',
        rgcData: {},
        company: {}
    },

    onLoad(query){
        const BMap = new bmap.BMapWX({
            ak
        });


        const fail = (data) => {
            console.log(data)
        };
        const success = (data) => {
            wxMarkerData = data.wxMarkerData;
            this.setData({
                markers: wxMarkerData,
                latitude: wxMarkerData[0].latitude,
                longitude: wxMarkerData[0].longitude
            });
        };
        BMap.regeocoding({
            location: `${query.latitude},${query.longitude}`,
            fail: fail,
            success: success,
            iconPath: '../../assets/marker_red.png',
        });

        app.getCompanyDetail().then((res) => {

            const {clerks, company, sales} = res;

            this.setData({company});
        })
    },

    onCallClick(){
        wx.makePhoneCall({
            phoneNumber: this.data.company.phoneNum || ''
        })
    },
});
